Skip to content

Conversation

@tjzel
Copy link
Contributor

@tjzel tjzel commented Aug 14, 2025

Summary:

At the moment user-made TurboModules are discovered during the evaluation of the script - conversely to Android, where it happens before this evaluation. Because of that it's impossible to instantiate a module that we don't know the name of pre-bundle.

To implement this I used modulesProvider codegen config field to get the names of the TurboModules and initialize their holders early.

Changelog:

[IOS] [ADDED] - Added ability to discover TurboModules pre-bundle.

Test Plan:

Before After
Screenshot 2025-08-14 at 20 49 09 Screenshot 2025-08-14 at 20 47 07

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 14, 2025
@tjzel tjzel force-pushed the @tjzel/ios-turbo-module-discovery branch from deb7658 to b1984c7 Compare August 14, 2025 18:50
@tjzel tjzel marked this pull request as ready for review August 14, 2025 19:13
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 14, 2025
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I left a few comments that has to be addressed.
This feature might also create some performance issues, delaying the app startup.
It would be great if you can wrap the _discoverModules in a featureFlag check, so we can disable it if we have a regression in the startup performance.

Feature flags for React Native are documented here


@protocol RCTTurboModuleManagerDelegate <NSObject>

- (nonnull NSArray<NSString *> *)getModuleNames;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change. every implementer of the delegate will have to implement this.
It is better to move this to be optional and to handle the optionality.

Also, the documentation is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know there is an application for multiple delegate implementers. I'll make it optional as you suggest and add relevant documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e3db6d5.

#pragma mark - Private Methods

- (void)_discoverModules{
NSArray<NSString *> *moduleNames = [_delegate getModuleNames];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, make the method in the delegate @optional, and handle this here like:

if ([_delegate respondsToSelector:@selector(getModuleNames)]) {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e3db6d5.

#pragma mark - RCTTurboModuleManagerDelegate

- (nonnull NSArray<NSString *> *)getModuleNames{
return [_delegate getModuleNames];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check whether the delegate implements this method or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e3db6d5.

}

- (nonnull NSArray<NSString *> *)getModuleNames{
return [dependencyProvider moduleNames];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check whether the dependencyProvider implement this method.
People could, in principle, create custom dependency providers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e3db6d5.

@react-native-bot
Copy link
Collaborator


Warnings
⚠️ ❗ JavaScript API change detected - This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API. Please include a clear changelog message. This change will be subject to extra review.

This change was flagged as: BREAKING

Generated by 🚫 dangerJS against e3db6d5

@tjzel
Copy link
Contributor Author

tjzel commented Aug 15, 2025

Thanks for the review! I tested the changes flipping the feature flag on and off and it worked as expected.

@RSNara
Copy link
Contributor

RSNara commented Aug 15, 2025

@tjzel, could you elaborate on the motivation behind this change? Why do we need the module holders initialized early?

@tjzel
Copy link
Contributor Author

tjzel commented Aug 18, 2025

@RSNara I talked about it in this comment #53282 (comment), early module holder initialization was for the purpose of finding modules conforming to a certain protocol.

@tjzel
Copy link
Contributor Author

tjzel commented Sep 25, 2025

Closing in favor of #53928

@tjzel tjzel closed this Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants